package com.game.dubbo.hall;

import com.game.message.Msg;
import com.game.message.jpb.JPbUtil;
import com.game.message.messagecode.DubboMsg;
import com.game.message.messagecode.MsgStage;
import com.game.message.task.AbstractDubboProcessor;
import com.game.messagebean.dubbo.RegisteReq;
import com.game.messagebean.dubbo.RegisteResp;
import com.game.mongo.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * Created by legend9999 on 2016/4/25.
 */
@Component
public class RegisteProcessor extends AbstractDubboProcessor {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    public Class getRequestClass() {
        return RegisteReq.class;
    }

    public int getMsgId() {
        return MsgStage.REQ + DubboMsg.Regist;
    }

    public Msg process(Msg msg, int userId) {
        RegisteReq pb = JPbUtil.getPb(RegisteReq.class, msg);
        logger.info("registe success...");
        User user = new User(pb.getLoginName(), pb.getPassword());
        user.setUserId(userMongo.getNextUserId());
        userMongo.addUser(user);

        RegisteResp registeRespBean = new RegisteResp();
        registeRespBean.setMessage("registe success...");
        registeRespBean.setResult((byte) 1);
        registeRespBean.setServerTime(System.currentTimeMillis());

        return JPbUtil.getMsg(RegisteResp.class, registeRespBean);
    }
}
